
//
//  GQInfomationController.m
//  GuQu
//
//  Created by HELIUM STAR on 15/5/6.
//  Copyright (c) 2015年 HELIUM STAR. All rights reserved.
//

#import "GQInfomationController.h"
#import "GQRegisterInfo.h"
#import "TipView.h"
#define kIntroMargin 20
#define kIntroHeight 44

@interface GQInfomationController ()

@property (weak, nonatomic) UITextField *textField;

@end

@implementation GQInfomationController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.frame = CGRectMake(0, kNavigatationBarHeight, kScreenWidth, kScreenHeight);
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageWithOriginalName:@"distribute_back"] style:UIBarButtonItemStylePlain target:self action:@selector(backToPre)];
    self.navigationItem.title = @"个人头衔";
    
    
    UIButton *rightItem = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 35, 20)];
    [rightItem setTitle:@"保存" forState:UIControlStateNormal];
    [rightItem setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    rightItem.titleLabel.font = [UIFont systemFontOfSize:14];
    [rightItem addTarget:self action:@selector(saveItemDidClick) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightItem];
    
    [self setUpChildView];
}

- (void)backToPre
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)saveItemDidClick
{
    NSString *text = [self.textField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
    NSRange range = [text rangeOfString:@" "];
    if (range.length) {
        [TipView showToView:self.view tipImage:[UIImage imageNamed:@"login_sad"] tipText:@"有非法字符"];
    }else{
        [GQRegisterInfo sharedGQRegisterInfo].honour = text;
        [TipView showToView:self.view tipImage:[UIImage imageNamed:@"login_smile"] tipText:@"保存成功"];
    }
}

- (void)setUpChildView
{
    //介绍自己
    UITextField *introTextField = [[UITextField alloc] initWithFrame:CGRectMake(0, kIntroMargin + kNavigatationBarHeight, kScreenWidth, kIntroHeight)];
    self.textField = introTextField;
    [self.view addSubview:introTextField];
    introTextField.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 15, kIntroHeight)];
    introTextField.leftViewMode = UITextFieldViewModeAlways;
    introTextField.placeholder = @"身处古玩圈, 简单的介绍一下自己";
    introTextField.backgroundColor = [UIColor whiteColor];
    
    //提示信息
    NSString *str = @"大家都在说：\n身份型：杭州市博物馆的管理员\n爱好型：杭州市西湖区古铜镜爱好者。\n\n亮出你的真实信息与爱好可以加速涨粉\n更早寻找到你志同道合的藏友";
    UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(kIntroMargin, CGRectGetMaxY(introTextField.frame) + kIntroMargin, kScreenWidth - 2 * kIntroMargin, 150)];
    textView.backgroundColor = [UIColor clearColor];
    textView.font = [UIFont systemFontOfSize:13];
    textView.text = str;
    textView.editable = NO;
    [self.view addSubview:textView];
    
}

@end
